﻿#include <VFAdapterAPIs.h>
#include <vf_oldapi.h>
#include <Windows.h>
#include <boost/algorithm/string.hpp>
#include <boost/program_options.hpp>
#include <cassert>
#include <combaseapi.h>
#include <comutil.h>
#include <format>
#include <iostream>
#include <test.h>
#include <fstream>
#include <mbdTreeNodeUtil .h>
#include <filesystem>

namespace tt {
void LinkCAD() {
  // 连接天工CAD验证
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  std::cout << "连接天工CAD状态:"
            << (status == VFAdapter::vf_Success ? "成功" : "失败") << std::endl;
}

// 创建点
void CreatePoint(std::string const &ptStr) {
  double x, y, z;
  if (!ptStr.empty()) {
    std::vector<std::string> resStr;
    boost::split(resStr, ptStr, boost::is_any_of(","),
                 boost::token_compress_on);
    if (resStr.size() != 3) {
      std::cout << "输入点坐标必须3个，以逗号分割" << std::endl;
      return;
    }
    x = std::stod(resStr[0]);
    y = std::stod(resStr[1]);
    z = std::stod(resStr[2]);
  }
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  // 创建点
  const char *ptID = nullptr;
  status = VFAdapter::vfCreatePoint(x, y, z, ptID);
  if (status == VFAdapter::vf_Success) {
    std::cout << "创建点:" << std::format("{0:3g},{1:3g},{2:3g}", x, y, z)
              << (status == VFAdapter::vf_Success ? "成功" : "失败")
              << std::format("点ID是{}", ptID) << std::endl;
    free((void *)ptID);
  }
}

void CvCv_IntersectPoint(std::vector<std::string> const &cvIds) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  if (cvIds.size() != 2) {
    std::cout << "输入的曲线ID必须是两个" << std::endl;
    return;
  }

  std::string idFstCvStr = cvIds[0];
  std::string idSndCvStr = cvIds[1];
  double interX, interY, interZ;
  interX = interY = interZ = 0;

  const char *outIntersectPtStr = nullptr;
  status = VFAdapter::vfCurveCurveIntersection(
      idFstCvStr.c_str(), idSndCvStr.c_str(), interX, interY, interZ,
      outIntersectPtStr);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("曲线曲线相交点:{0:3g},{1:3g},{2:3g},点ID:{3}",
                             interX, interY, interZ, outIntersectPtStr);
    free((void *)outIntersectPtStr);
  } else {
    std::cout << "未计算得交点" << std::endl;
  }
}

// 镜像创建面
void CreateMirrorSurface(const std::vector<std::string> &sParam) {

  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  std::string surfaceID = sParam[0];
  std::string mirrorPlaneID = sParam[1];
  const char *mirrorSurfaceID = nullptr;
  bool bReserved = false;
  status = VFAdapter::vfMirrorSurface(surfaceID.c_str(), mirrorPlaneID.c_str(),
                                      bReserved, mirrorSurfaceID);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("镜像面成功,新面ID:{0}", mirrorSurfaceID)
              << std::endl;
  } else {
    std::cout << "镜像面失败" << std::endl;
  }
}
// 通过投影创建投影曲线
void CreateCurveByProjection(const std::vector<std::string> &sParam) {

  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  std::string curveID1 = sParam[0];
  std::string surfaceID = sParam[1];
  const char *curveID2 = nullptr;
  status = VFAdapter::vfCreateCurveByProjection(curveID1.c_str(),
                                                surfaceID.c_str(), curveID2);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("曲线投影成功,新曲线ID:{0}", curveID2)
              << std::endl;
  } else {
    std::cout << "曲线投影失败" << std::endl;
  }
  if (curveID2) {
    free((void *)curveID2);
  }
}

// 样条曲线
void Vf_CreateSplineCurve(const std::vector<std::string> &sParam) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  int count = sParam.size();
  std::vector<const char *> points;
  for (auto const &str : sParam) {
    points.push_back(str.c_str());
  }
  bool bControl = false;
  const char *lCurveId = nullptr;
  status =
      VFAdapter::vfCreateSplineCurve(points.data(), count, bControl, lCurveId);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("样条曲线创建成功,新曲线ID:{0}", lCurveId)
              << std::endl;
  } else {
    std::cout << "样条曲线创建失败" << std::endl;
  }
  if (lCurveId) {
    free((void *)lCurveId);
  }
}

// 曲线在曲面上偏置
void Vf_CreateOffsetCurve(std::vector<std::string> const &eleIds) {

  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  if (eleIds.size() != 2) {
    std::cout << "输入的元素ID必须是两个,第一个为曲线ID，第二个为曲面ID"
              << std::endl;
    return;
  }

  std::string curveID1 = eleIds[0];
  std::string surfaceID = eleIds[1];
  double dis = 0.0;
  const char *curveID2 = nullptr;
  status = VFAdapter::vfOffsetCurve(curveID1.c_str(), surfaceID.c_str(), dis,
                                    curveID2);
  if (VFAdapter::vf_Success == status) {
    std::cout << std::format("偏置曲线成功，新曲线ID:{0}", curveID2)
              << std::endl;
  } else {
    std::cout << "偏置曲线失败" << std::endl;
  }
}

void Vf_CreateCurveSurfaceIntersection(std::vector<std::string> const &eleIds) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  if (eleIds.size() != 2) {
    std::cout << "输入的元素ID必须是两个,第一个为曲线ID，第二个为曲面ID"
              << std::endl;
    return;
  }

  std::string idCvStr = eleIds[0];
  std::string idSurfStr = eleIds[1];
  double x, y, z;
  bool bCreatePoint = true;
  const char *ptID = nullptr;
  status = VFAdapter::vfCurveSurfaceIntersection(
      idCvStr.c_str(), idSurfStr.c_str(), x, y, z, ptID);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("曲线曲面相交点:{0:3g},{1:3g},{2:3g},点ID:{3}", x,
                             y, z, ptID);
    free((void *)ptID);
  }
}

// 曲面沿法向偏置
void Vf_OffsetSurface(std::vector<std::string> const &vParams) {

  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  if (vParams.size() != 3) {
    std::cout << "输入的参数必须是3个,第一个为方向点ID,"
                 "第二个为曲面ID，第三个为偏移距离"
              << std::endl;
    return;
  }
  std::string directionPointID = vParams[0];
  std::string surfaceID = vParams[1];
  double dis = std::stod(vParams[2]);
  const char *offsetSurfaceID = nullptr;
  status = VFAdapter::vfOffsetSurface(
      surfaceID.c_str(), directionPointID.c_str(), dis, offsetSurfaceID);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("偏置曲面成功，新曲面ID:{0}", offsetSurfaceID)
              << std::endl;
    free((void *)offsetSurfaceID);
  } else {
    std::cout << "偏置曲面失败" << std::endl;
  }
}

//
void S2S_IntersectCurve(std::vector<std::string> const &faceIds) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  if (faceIds.size() != 2) {
    std::cout << "输入的曲线ID必须是两个" << std::endl;
    return;
  }

  std::string idSurfFstStr = faceIds[0];
  std::string idSurfSndStr = faceIds[1];
  const char *idOutCvStr = nullptr;
  status = VFAdapter::vfCreateCurveBySurfaceIntersection(
      idSurfFstStr.c_str(), idSurfSndStr.c_str(), idOutCvStr);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("求得交线成功,交线ID:{0}", idOutCvStr);
    free((void *)idOutCvStr);
  } else {
    std::cout << "未计算得交点" << std::endl;
  }
}

void TestGetEntityType(std::string entId) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  VFAdapter::geom_entity_type geomType;
  status = VFAdapter::vfGetEntityType(entId.c_str(), geomType);
  if (status != VFAdapter::vf_Success) {
    std::cout << "获得实体类型有误" << std::endl;
    return;
  }
  std::string_view geomTypeStr = "";
  switch (geomType) {
  case VFAdapter::vf_vertex:
    geomTypeStr = "点";
    break;
  case VFAdapter::vf_curve:
    geomTypeStr = "线";
    break;
  case VFAdapter::vf_face:
    geomTypeStr = "面";
    break;
  case VFAdapter::vf_body:
    geomTypeStr = "体";
    break;
  default:
    geomTypeStr = "暂不支持";
    break;
  }
  std::cout << "类型是" << geomTypeStr << std::endl;
}

void TestSelMul(int typeIdx) {
  if (typeIdx < 1 || typeIdx > 5) {
    std::cout << "仅允许输入[1-5],点:1,曲线:2,面:3,链:4,体:5" << std::endl;
    return;
  }
  VFAdapter::geom_entity_type geomType;
  if (typeIdx == 1)
    geomType = VFAdapter::vf_vertex;
  if (typeIdx == 2)
    geomType = VFAdapter::vf_curve;
  if (typeIdx == 3)
    geomType = VFAdapter::vf_face;
  if (typeIdx == 4)
    geomType = VFAdapter::vf_loop;
  if (typeIdx == 5)
    geomType = VFAdapter::vf_body;
  const wchar_t *promptMsg = L"选中xxx";
  std::vector<int64_t> tagIDs;
  VFAdapter::vfHRESULT status = VFAdapter::vfSelectMultiyInteractive(
      geomType, tagIDs, const_cast<wchar_t *>(promptMsg), false);
  if (status == VFAdapter::vf_Success) {
    std::cout << "选中成功,选中个数为:" << tagIDs.size() << std::endl;
  } else if (status == VFAdapter::vf_Cancel) {
    std::cout << "取消选择" << std::endl;
  } else if (status == VFAdapter::vf_Failure) {
    std::cout << "未选中" << std::endl;
  }
}

void TestSelectInteractive(int typeIdx) {

  if (typeIdx < 1 || typeIdx > 5) {
    std::cout << "仅允许输入[1-5],点:1,曲线:2,面:3,链:4,体:5" << std::endl;
    return;
  }
  VFAdapter::geom_entity_type geomType;
  if (typeIdx == 1)
    geomType = VFAdapter::vf_vertex;
  if (typeIdx == 2)
    geomType = VFAdapter::vf_curve;
  if (typeIdx == 3)
    geomType = VFAdapter::vf_face;
  if (typeIdx == 4)
    geomType = VFAdapter::vf_loop;
  if (typeIdx == 5)
    geomType = VFAdapter::vf_body;

  int64_t tagID = -1;
  const wchar_t *promptMsg = L"选中xxx";
  VFAdapter::vfHRESULT status = VFAdapter::vfSelectSingleByInteractive(
      geomType, tagID, const_cast<wchar_t *>(promptMsg), false);
  if (status == VFAdapter::vf_Success) {
    std::cout << "选中成功,ID为:" << tagID << std::endl;
  } else if (status == VFAdapter::vf_Cancel) {
    std::cout << "取消选择" << std::endl;
  } else if (status == VFAdapter::vf_Failure) {
    std::cout << "未选中" << std::endl;
  }
}

void TestIntersect_S2S(std::vector<std::string> const &surfIds) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  if (surfIds.size() != 2) {
    std::cout << "请输入两个曲面的ID来进行运算" << std::endl;
    return;
  }

  std::string idSurfFst = surfIds[0];
  std::string idSurfSnd = surfIds[1];

  const char *curveID = nullptr;
  VFAdapter::vfHRESULT res = VFAdapter::vfCreateCurveBySurfaceIntersection(
      idSurfFst.c_str(), idSurfSnd.c_str(), curveID);
  if (res == VFAdapter::vf_Success) {
    std::cout << std::format("成功计算交线,交线ID为{}", curveID) << std::endl;
    free((void *)curveID);
  } else {
    std::cout << "不存在交线或计算有误" << std::endl;
  }
}

void TestSelByTag(std::string entId) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  status = VFAdapter::vfSelectByTag(entId.c_str());
  if (status == VFAdapter::vf_Success) {
    std::cout << "已选择成功" << std::endl;
  } else {
    std::cout << "运行失败" << std::endl;
  }
}

void TestClearSelection() {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  status = VFAdapter::vfClearSeletion();
  if (status == VFAdapter::vf_Success) {
    std::cout << "已清空选择集" << std::endl;
  } else {
    std::cout << "运行失败" << std::endl;
  }
}
// 边界填充曲面
void CreateSurfaceByFill(const std::vector<std::string> &sParam) {

  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  if (sParam.size() == 0) {
    std::cout << "请输入边的ID" << std::endl;
    return;
  }

  int size = sParam.size();
  std::vector<int64_t> curveIds;
  for (auto &id : sParam) {
    curveIds.push_back(std::stoull(id));
  }
  int64_t newSurfaceID = 0;
  status =
      VFAdapter::vfCreateSurfaceByFill_old(curveIds.data(), size, newSurfaceID);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("创建填充曲面成功{}", newSurfaceID) << std::endl;
  } else {
    std::cout << "创建填充曲面失败" << std::endl;
  }
  if (newSurfaceID) {
    free((void *)newSurfaceID);
  }
}

// 曲面上两点创建曲线
void CreateCurveOnSurfaceByTwoPoints(const std::string &arg) {

  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  std::vector<std::string> sParam;
  boost::split(sParam, arg, boost::is_any_of(" "));
  if (sParam.size() != 7) {
    std::cout << "请输入7组参数,前6组参数分别代表X1,Y1,Z1,X2,Y2,"
                 "Z2,每组参数中点坐标用逗号隔开。最后一组参数为曲面"
              << std::endl;
    return;
  }

  // 提取字符串的中数字并组成数组
  auto ExtractDoubleArr = [](const std::string &str) -> std::vector<double> {
    std::vector<std::string> splitRes;
    boost::split(splitRes, str, boost::is_any_of(","),
                 boost::token_compress_on);
    std::vector<double> res;
    for (auto const &valueStr : splitRes) {
      res.push_back(std::stod(valueStr));
    }
    // 约定：最后一个参数为NAN为终止
    res.push_back(NAN);
    return res;
  };

  std::vector<double> x1 = ExtractDoubleArr(sParam[1]);
  std::vector<double> y1 = ExtractDoubleArr(sParam[2]);
  std::vector<double> z1 = ExtractDoubleArr(sParam[3]);
  std::vector<double> x2 = ExtractDoubleArr(sParam[4]);
  std::vector<double> y2 = ExtractDoubleArr(sParam[5]);
  std::vector<double> z2 = ExtractDoubleArr(sParam[6]);
  std::string surfaceID = sParam[0];
  status = VFAdapter::vfCreateCurveOnSurfaceByTwoPoints(
      x1.data(), y1.data(), z1.data(), x2.data(), y2.data(), z2.data(),
      surfaceID.c_str());
  if (status == VFAdapter::vf_Success) {
    std::cout << "在曲面上根据点创建曲线成功" << std::endl;
  } else {
    std::cout << "在曲面上根据点创建曲线失败" << std::endl;
  }
}
// 镜像创建曲线
void CreateMirrorCurve(const std::vector<std::string> &sParam) {

  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  std::string curveID = sParam[0];
  std::string planeID = sParam[1];
  const char *curveID2 = nullptr;
  status = VFAdapter::vfMirrorCurve(curveID.c_str(), planeID.c_str(), true,
                                    curveID2);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("镜像成功,曲线ID为{}", curveID2) << std::endl;
  } else {
    std::cout << "镜像失败" << std::endl;
  }
  if (curveID2) {
    free((void *)curveID2);
  }
}
// 通过曲面加厚创建体
void CreateBodyWithThickedSurface(const std::vector<std::string> &sParam) {

  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  std::string surfaceID = sParam[0];
  double thickness = 0.01;
  const char *bodyID = nullptr;
  status = VFAdapter::vfCreateBodyWithThickedSurface(surfaceID.c_str(),
                                                     thickness, bodyID);
  if (bodyID) {
    free((void *)bodyID);
  }
}

// 计算曲面的周长和面积
void CalSurfaceAreaAndPerimeter(const std::string &sParam) {

  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  std::string surfaceID = sParam;
  double area = 0.0;
  status = VFAdapter::vfSurfaceArea(surfaceID.c_str(), area);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("曲面面积为{}", area) << std::endl;
  } else {
    std::cout << "计算曲面面积失败" << std::endl;
  }
  double perimeter = 0.0;
  status = VFAdapter::vfSurfacePerimeter(surfaceID.c_str(), perimeter);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("曲面周长为{}", perimeter) << std::endl;
  } else {
    std::cout << "计算曲面周长失败" << std::endl;
  }
}

// 多曲线创建截面
void CreateSurfaceByLoft(const std::vector<std::string> &sParam) {

  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  std::vector<const char *> curveIds;
  for (auto const &curveId : sParam) {
    curveIds.push_back(curveId.c_str());
  }

  const char *newSurfaceID = nullptr;
  status = VFAdapter::vfCreateSurfaceByLoft(curveIds.data(), curveIds.size(),
                                            newSurfaceID);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("创建截面成功{}", newSurfaceID) << std::endl;
  } else {
    std::cout << "创建截面失败" << std::endl;
  }
  if (newSurfaceID) {
    free((void *)newSurfaceID);
  }
}

//
void CalSurfaceMass(std::vector<std::string> const &paraArr) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  if (paraArr.size() != 2) {
    std::cout << "请输入两个参数，参数1为封装曲面ID，参数2为密度" << std::endl;
    return;
  }

  int64_t surfaceID = 1;
  double dWeight = 0.0;
  std::string faceIdStr = paraArr[0];
  double dDense = std::stod(paraArr[1]);
  status = VFAdapter::vfSurfaceWeight(faceIdStr.c_str(), dDense, dWeight);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("曲面质量计算成功{}", dWeight) << std::endl;
  } else {
    std::cout << "曲面质量计算失败" << std::endl;
  }
}

void CalcSurfGravity(std::string const &faceId) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  double x, y, z;
  std::string faceIdStr = faceId;
  status = VFAdapter::vfCreateGravityOfSurface(faceIdStr.c_str(), x, y, z);
  if (status == VFAdapter::vf_Success) {
    const char *ptId = nullptr;
    VFAdapter::vfCreatePoint(x, y, z, ptId);
    std::cout << std::format("重力为({},{},{})", x, y, z) << std::endl;
    if (ptId) {
      free((void *)ptId);
    }
  } else {
    std::cout << "重力计算失败" << std::endl;
  }
}

//
void CreateSurfaceMerge(const std::vector<std::string> &vParam) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  std::vector<const char *> vIds;
  for (auto const &str : vParam) {
    vIds.push_back(str.c_str());
  }
  int size = vParam.size();

  const char *idSurf = nullptr;
  status = VFAdapter::vfSurfaceMerge(vIds.data(), size, idSurf);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("曲面合并成功，新的曲面ID为{}", idSurf)
              << std::endl;
  } else {
    std::cout << "曲面合并失败" << std::endl;
  }
}

void TestMousePtOnSurface(std::string surfId) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  double x, y, z;

  status = VFAdapter::vfMousePtOnSurface(surfId.c_str(), x, y, z);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("交互地在曲面{}上取到的的坐标为({},{},{})", surfId,
                             x, y, z)
              << std::endl;
    const char *ptId = nullptr;
    status = VFAdapter::vfCreatePoint(x, y, z, ptId);
    if (status == VFAdapter::vf_Success) {
      std::cout << std::format("create point success,the point id is {}", ptId)
                << std::endl;
    }
    if (ptId) {
      free((void *)ptId);
    }
  }
}

void TestMirrorObject(std::vector<std::string> const &ids) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  if (ids.size() != 2) {
    std::cout
        << "请输入两个ID，第一个为待镜像的特征的id，第二个镜像的平面的id。"
        << std::endl;
    return;
  }

  std::string idObj = ids[0];
  std::string idPlane = ids[1];
  const char *idObj2 = nullptr;
  status =
      VFAdapter::vfMirrorObject(idObj.c_str(), idPlane.c_str(), true, idObj2);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("镜像成功，新的对象ID为{}", idObj2) << std::endl;
  }
  if (idObj2) {
    free((void *)idObj2);
  }
}

void TestCreateComponentCv(std::vector<std::string> ids) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  if (ids.empty()) {
    std::cout << "输入参数为空" << std::endl;
    return;
  }

  std::vector<const char *> idsStr;
  for (auto const &id : ids) {
    idsStr.push_back(id.c_str());
  }

  bool reserved = true;
  const char *cvId = nullptr;
  status = VFAdapter::vfCreateCurveByMultiCurves(idsStr.data(), idsStr.size(),
                                                 reserved, cvId);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("创建曲线成功，曲线ID为{}", cvId) << std::endl;
  }
  if (cvId) {
    free((void *)cvId);
  }
}

void TestCurveTrim(std::vector<std::string> const &ids) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  if (ids.size() != 2) {
    std::cout << "请输入两个ID，第一个为曲线的id，第二个为裁剪的曲线的id。"
              << std::endl;
  }
  const char *outCvId = nullptr;
  status = VFAdapter::vfCurveTrim(ids[0].c_str(), ids[1].c_str(), outCvId);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("裁剪成功，新的曲线ID为{}", outCvId) << std::endl;
  }
  if (outCvId) {
    free((void *)outCvId);
  }
}

void TestCtPtByU(std::string const &arg) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  if (arg.empty())
    return;

  std::vector<std::string> resStr;
  boost::split(resStr, arg, boost::is_any_of(","), boost::token_compress_on);
  if (resStr.size() != 2) {
    std::cout << "输入两个参数，以逗号分割;第一个为id,第二个为u" << std::endl;
    return;
  }
  int64_t cvId = std::stoi(resStr[0]);
  double u = std::stod(resStr[1]);
  double x, y, z;
  const char *ptId = nullptr;
  status = VFAdapter::vfCreatePointOnCurve(resStr[0].c_str(), u, x, y, z, ptId);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("创建点成功，点的ID为{0},坐标为{1},{2},{3}", ptId,
                             x, y, z)
              << std::endl;
  }
  if (ptId) {
    free((void *)ptId);
  }
}

void TestCtPtByUV(std::string const &arg) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  if (arg.empty())
    return;

  std::vector<std::string> resStr;
  boost::split(resStr, arg, boost::is_any_of(","), boost::token_compress_on);
  if (resStr.size() != 3) {
    std::cout << "输入三个参数，以逗号分割;第一个为id,第二个为u,第三个为v"
              << std::endl;
    return;
  }

  double u = std::stod(resStr[1]);
  double v = std::stod(resStr[2]);
  double x, y, z;
  const char *ptId = nullptr;
  status =
      VFAdapter::vfCreatePointOnSurface(resStr[0].c_str(), u, v, x, y, z, ptId);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("创建点成功，点的ID为{0},坐标为{1},{2},{3}", ptId,
                             x, y, z)
              << std::endl;
  }
  if (ptId) {
    free((void *)ptId);
  }
}
std::wstring Utf8ToUnicode(const char *utf8) {
  int len;
  len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
  wchar_t *unicode = new wchar_t[len];
  memset(unicode, 0, len * sizeof(wchar_t));
  MultiByteToWideChar(CP_UTF8, 0, utf8, -1, unicode, len);
  std::wstring wstrUnicode = unicode;
  delete[] unicode;
  return wstrUnicode;
}
void TestCtFuncCurve(std::string const &arg) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  if (arg.empty())
    return;

  std::vector<std::string> resStr;
  boost::split(resStr, arg, boost::is_any_of(";"), boost::token_compress_on);
  if (resStr.size() != 4) {
    std::cout
        << "输入四个参数，以分号分割;第一个为坐标类型;第二、三、四均为表达式"
        << std::endl;
    return;
  }
  int cType = std::stoi(resStr[0]);
  std::wstring expr1 = Utf8ToUnicode(resStr[1].data());
  std::wstring expr2 = Utf8ToUnicode(resStr[2].data());
  std::wstring expr3 = Utf8ToUnicode(resStr[3].data());
  const char *cvId = nullptr;
  status = VFAdapter::vfCreateFunctionCurve(cType, expr1.data(), expr2.data(),
                                            expr3.data(), cvId);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("创建方程曲线成功，曲线ID为{}", cvId) << std::endl;
  }
  if (cvId) {
    free((void *)cvId);
  }
}

void TestChWidClr(std::string const &cvId) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  int32_t lineWId;
  int32_t r, g, b;
  status =
      VFAdapter::vfChangeTheColorLineWidth(cvId.c_str(), &lineWId, &r, &g, &b);
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format(
        "已变更曲线线宽和颜色,原始线宽为{0},颜色为{1},{2},{3}", lineWId, r, g,
        b);
  }
}

void TestRestoreWidClr(std::string const &cvId) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  status = VFAdapter::vfRestoresColorLineWidth(cvId.c_str());
  if (status == VFAdapter::vf_Success) {
    std::cout << "已恢复曲线原始线宽和颜色" << std::endl;
  }
}

void TestCtCoordSysById(std::string const &arg) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  if (arg.empty())
    return;

  std::vector<std::string> resArr;
  boost::split(resArr, arg, boost::is_any_of(","), boost::token_compress_on);
  if (resArr.size() != 6) {
    std::cout << "输入六个参数，以逗号分割;第一个为曲面ID,"
                 "第二个点ID，第三个为线ID，第四个为起始角，第五个为方向角，第"
                 "七个为线段长度"
              << std::endl;
    return;
  }

  int64_t surfId = std::stoi(resArr[0]);
  int64_t ptId = std::stoi(resArr[1]);
  int64_t cvId = std::stoi(resArr[2]);
  double startAngle = std::stod(resArr[3]);
  double dirAngle = std::stod(resArr[4]);
  double len = std::stod(resArr[5]);
  std::array<int64_t, 6> resLine;
  int64_t rosseteId;
  status = VFAdapter::vfCreateRosetteById(
      surfId, ptId, cvId, startAngle, dirAngle, len, true, &rosseteId,
      &resLine[0], &resLine[1], &resLine[2], &resLine[3], &resLine[4],
      &resLine[5]);
  if (status == VFAdapter::vf_Success) {
    std::cout
        << std::format(
               "创建坐标系成功，坐标系六个边为ID为{0},{1}, {2}, {3}, {4}, {5}",
               resLine[0], resLine[1], resLine[2], resLine[3], resLine[4],
               resLine[5])
        << std::endl;
  }
}

void TestRemoveObj(std::string const &objId) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  status = VFAdapter::vfRemoveTargetObject(objId.c_str());
  if (status == VFAdapter::vf_Success) {
    std::cout << std::format("删除对象{0}成功", objId) << std::endl;
  }
}

void TestBatchChClrWid(std::string const &arg) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  std::vector<std::string> resStr;
  boost::split(resStr, arg, boost::is_any_of(","), boost::token_compress_on);
  if (resStr.empty()) {
    std::cout << "输入至少一个拓扑对象ID，如有多个对象时以逗号分割"
              << std::endl;
    return;
  }
  std::vector<const char *> idArr;
  for (auto &str : resStr) {
    idArr.push_back(str.data());
  }
  idArr.push_back(nullptr);
  status = VFAdapter::vfChangeLineColorWidthInsertMap(idArr.data());
  if (status == VFAdapter::vf_Success) {
    std::cout << "批量变更颜色和线宽成功" << std::endl;
  } else {
    std::cout << "批量变更颜色和线宽失败" << std::endl;
  }
}
void TestBatchClearClrWid(std::string const &arg) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  std::vector<std::string> resStr;
  boost::split(resStr, arg, boost::is_any_of(","), boost::token_compress_on);
  if (resStr.empty()) {
    std::cout << "输入至少一个拓扑对象ID，如有多个对象时以逗号分割"
              << std::endl;
    return;
  }
  std::vector<const char *> idArr;
  for (auto &str : resStr) {
    idArr.push_back(str.data());
  }
  idArr.push_back(nullptr);

  status = VFAdapter::vfChangeLineColorWidthFromMap(idArr.data());
  if (status == VFAdapter::vf_Success) {
    std::cout << "批量恢复颜色和线宽成功" << std::endl;
  } else {
    std::cout << "批量恢复颜色和线宽失败" << std::endl;
  }
}
void TestSectionToId(std::string const &arg) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  const wchar_t *filterType = L"Point,Curve";
  // filterType= L"Point", L"Curve", L"Surface";
  char intValue[256] = {0};
  status = VFAdapter::vfSelectionToID(filterType, intValue);

  int aaa = 0;
}

void TestvfCreatPointByGeodesicDis(std::string const &arg) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  std::vector<std::string> resStr;
  boost::split(resStr, arg, boost::is_any_of(","), boost::token_compress_on);
  if (resStr.size() != 6) {
    std::cout << "输入至少一个拓扑对象ID，如有多个对象时以逗号分割"
              << std::endl;
    return;
  }

  std::string pointId = resStr[0];
  std::string faceId = resStr[1];
  double x = std::stod(resStr[2]);
  double y = std::stod(resStr[3]);
  double z = std::stod(resStr[4]);
  double geodesicDis = std::stod(resStr[5]);

  const char *outPointId;
  status = VFAdapter::vfCreatPointByGeodesicDis(
      faceId.data(), pointId.data(), x, y, z, geodesicDis, outPointId);
}

void TestPointOnCurve(std::vector<std::string> const &ids) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  if (ids.size() != 2) {
    std::cout << "请输入两个参数，参数一为点ID，参数二为曲线ID" << std::endl;
    return;
  }
  std::string idCurveStr = ids[1];
  std::string idPointStr = ids[0];
  bool bOn = false;
  status = VFAdapter::vfTestPointOnCurve(idPointStr.c_str(), idCurveStr.c_str(),
                                         bOn);
  if (status == VFAdapter::vf_Success) {
    std::cout << "点" << (bOn ? "在" : "不在") << "曲线上" << std::endl;
  } else {
    std::cout << "计算点是否在线段上失败" << std::endl;
  }
}

void TestPointOnSurface(std::vector<std::string> const &ids) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  if (ids.size() != 2) {
    std::cout << "请输入两个参数，参数一为点ID，参数二为曲面ID" << std::endl;
    return;
  }
  std::string idPointStr = ids[0];
  std::string idSurfaceStr = ids[1];
  int res;
  status = VFAdapter::vfTestPointOnSurface(idPointStr.c_str(),
                                           idSurfaceStr.c_str(), res);
  if (status == VFAdapter::vf_Success) {
    if (res == 0) {
      std::cout << "点不在曲面上" << std::endl;
    } else if (res == 1) {
      std::cout << "点在曲面内部" << std::endl;
    } else if (res == 2) {
      std::cout << "点在曲面边界" << std::endl;
    }
  } else {
    std::cout << "计算点是否在曲面上失败" << std::endl;
  }
}

void TestPointOnSurface2(std::vector<std::string> const &parmArr) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);

  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  if (parmArr.size() != 4) {
    std::cout << "请输入四个参数，参数一为点X坐标，参数二为点Y坐标，参数三为点Z"
                 "坐标，参数四为曲面ID"
              << std::endl;
    return;
  }

  double x = std::stod(parmArr[0]);
  double y = std::stod(parmArr[1]);
  double z = std::stod(parmArr[2]);
  std::string idSurfaceStr = parmArr[3];
  int res;
  status = VFAdapter::vfTestPointOnSurface2(x, y, z, idSurfaceStr.c_str(), res);
  if (status == VFAdapter::vf_Success) {
    if (res == 0) {
      std::cout << "点不在曲面上" << std::endl;
    } else if (res == 1) {
      std::cout << "点在曲面内部" << std::endl;
    } else if (res == 2) {
      std::cout << "点在曲面边界" << std::endl;
    }
  } else {
    std::cout << "计算点是否在曲面上失败" << std::endl;
  }
}

void TestvfCurveLength(std::string const &cvId) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  double length = 0;
  status = VFAdapter::vfCurveLength(cvId.c_str(), length);
  if (status == VFAdapter::vf_Success) {
    std::cout << "curve length is " << length << std::endl;
  } else {
    std::cout << "calc curve length failed" << std::endl;
  }
}

void TestvfCreatePointByProjection(std::vector<std::string> const &idArr) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  if (idArr.size() != 2) {
    std::cout << "请输入两个参数，参数一为点ID，参数二为待投影的面ID"
              << std::endl;
    return;
  }
  std::string idPointStr = idArr[0];
  std::string idSurfaceStr = idArr[1];
  const char *idProjectPoint = nullptr;
  status = VFAdapter::vfCreatePointByProjection(
      idPointStr.c_str(), idSurfaceStr.c_str(), idProjectPoint);
  if (status == VFAdapter::vf_Success) {
    std::cout << "create point success, is is " << idProjectPoint << std::endl;
    delete idProjectPoint;
    int aa = 0;
  } else {
    std::cout << "create point failed" << std::endl;
  }
}
void TestTangentOnCurve(std::string const &arg) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  std::vector<std::string> argArr;
  boost::split(argArr, arg, boost::is_any_of(" "));
  if (argArr.size() != 2) {
    std::cout << "请输入两个参数，参数一为点ID，参数二为曲线ID" << std::endl;
  }

  std::string idPtStr = argArr[0];
  std::string idCurveStr = argArr[1];
  double x, y, z;
  status = VFAdapter::vfGetUnitTangentVectorAtPoint(
      idCurveStr.c_str(), idPtStr.c_str(), true, x, y, z);
  if (status == VFAdapter::vf_Success) {
    std::cout << "获得曲线上此点切向量成功" << std::endl;
  } else {
    std::cout << "获得曲线上此点切向量失败" << std::endl;
  }
}

void TestHilitPointSet(std::string const &arg) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  std::vector<std::string> argArr;
  boost::split(argArr, arg, boost::is_any_of(" "));
  if (argArr.empty()) {
    std::cout << "请输入两个参数，参数一为点ID，参数二为曲线ID" << std::endl;
  }

  const char **inputStringValue =
      new const char *[argArr.size() + 1] { nullptr };
  for (int i = 0; i < argArr.size(); i++) {
    inputStringValue[i] = argArr[i].c_str();
  }
  status =
      VFAdapter::vfChangePointColorInsertMap(inputStringValue, 255, 0, 255);
  if (status == VFAdapter::vf_Success) {
    std::cout << "highlight point set successfully" << std::endl;
  } else {
    std::cout << "highlight point set failed" << std::endl;
  }
  delete[] inputStringValue;
}

void TestClearHilitPointSet(std::string const &arg) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  std::vector<std::string> argArr;
  boost::split(argArr, arg, boost::is_any_of(" "));
  if (argArr.empty()) {
    std::cout << "请输入两个参数，参数一为点ID，参数二为曲线ID" << std::endl;
  }

  const char **inputStringValue =
      new const char *[argArr.size() + 1] { nullptr };
  for (int i = 0; i < argArr.size(); i++) {
    inputStringValue[i] = argArr[i].c_str();
  }
  status = VFAdapter::vfChangePointColorFromMap(inputStringValue);
  if (status == VFAdapter::vf_Success) {
    std::cout << "highlight point set successfully" << std::endl;
  } else {
    std::cout << "highlight point set failed" << std::endl;
  }
  delete[] inputStringValue;
}

void TestAddComment(std::string const &arg) {

  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  // status = VFAdapter::vfAddCommentOnPoint(arg.c_str(), "test");
  if (status != VFAdapter::vf_Success) {
    std::cout << "add comment failed" << std::endl;
  } else {
    std::cout << "add comment success " << std::endl;
  }
}

void TestDelComment(std::string const &arg) {

  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  status = VFAdapter::vfDeleteCommentOnPoint(arg.c_str());
  if (status != VFAdapter::vf_Success) {
    std::cout << "del comment failed" << std::endl;
  } else {
    std::cout << "del comment success " << std::endl;
  }
}

void TestGeodesicDisPoint(std::string const &arg) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "lick tgcad failed" << std::endl;
    return;
  };

  std::vector<std::string> argArr;
  boost::split(argArr, arg, boost::is_any_of(" "));

  if (argArr.size() != 6) {
    std::cout << "Please input 6 args ,0 is ptid,1 is faceid ,[2-4] is "
                 "direction,5 is distance "
              << std::endl;
    return;
  };

  std::string ptIdStr = argArr[0];
  std::string faceIdStr = argArr[1];
  double dirX = std::stod(argArr[2]);
  double dirY = std::stod(argArr[3]);
  double dirZ = std::stod(argArr[4]);
  double dis = std::stod(argArr[5]);

  const char *ptResId = nullptr;
  double resX, resY, resZ;
  status = VFAdapter::vfCreatPointByGeodesicDis2(faceIdStr.c_str(),
                                                 ptIdStr.c_str(), dirX, dirY,
                                                 dirZ, dis, resX, resY, resZ);
  if (VFAdapter::vf_Success == status) {
    std::cout << "create geodesic dis point,id is " << ptResId << std::endl;
    delete ptResId;
  } else {
    std::cout << "create geodesic dis point failed";
  }
}

void TestGeodesicDis(std::string const &arg) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "lick tgcad failed" << std::endl;
    return;
  };

  std::vector<std::string> argArr;
  boost::split(argArr, arg, boost::is_any_of(" "));

  if (argArr.size() != 6) {
    std::cout << "Please input 3 args ,0 is ptid,1 is edgeId ,2 is "
                 "faceId,[3-5] is dir"
              << std::endl;
    return;
  };

  std::string idPt = argArr[0];
  std::string idCurve = argArr[1];
  std::string idFace = argArr[2];
  double dirX = std::stod(argArr[3]);
  double dirY = std::stod(argArr[4]);
  double dirZ = std::stod(argArr[5]);
  double dis;
  status = VFAdapter::vfGeodesicLengthOfPointToCurve(
      idFace.c_str(), idCurve.c_str(), idPt.c_str(), dirX, dirY, dirZ, dis);
  if (VFAdapter::vf_Success == status) {
    std::cout << "get geodDis form pt to curve in face by dir success, dis is "
              << dis << std::endl;
  }
}

void TestIntersetCurves(std::string const &arg) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "lick tgcad failed" << std::endl;
    return;
  };

  const char **intersectCvIds = nullptr;
  status = VFAdapter::vfGetIntersectCurve(arg.c_str(), intersectCvIds);
  if (status == VFAdapter::vf_Success) {
    while (*intersectCvIds) {
      const char *idStr = *intersectCvIds;
      std::cout << "curve " << idStr << " is intersect with curve " << arg
                << std::endl;
      intersectCvIds++;
      free((void *)idStr);
    }
    delete[] intersectCvIds;
  } else {
    std::cout << "get curve instersect failed, or no curve intersect with "
              << arg << std::endl;
  }
}

void TestIsPointInProjectRange(std::string const &arg) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "lick tgcad failed" << std::endl;
    return;
  };

  std::vector<std::string> argArr;
  boost::split(argArr, arg, boost::is_any_of(" "));

  if (argArr.size() != 7) {
    std::cout << "Please input 7 args ,0 is faceId ,[1-3] is "
                 "point coord,[4-6] is projectDirection"
              << std::endl;
    return;
  };

  std::string idFace = argArr[0];
  double ptX = std::stod(argArr[1]);
  double ptY = std::stod(argArr[2]);
  double ptZ = std::stod(argArr[3]);

  double dirX = std::stod(argArr[4]);
  double dirY = std::stod(argArr[5]);
  double dirZ = std::stod(argArr[6]);

  int res;
  status = VFAdapter::vfTestPointOnSurfaceByProject(idFace.c_str(), ptX, ptY,
                                                    ptZ, dirX, dirY, dirZ, res);

  if (status == res) {
    if (res == 0) {
      std::cout << "can not project to face in this project dir" << std::endl;
    } else if (res == 1) {
      std::cout << "pt can project inside face in this project dir"
                << std::endl;
    } else if (res == 2) {
      std::cout << "pt can project on the boundary of face in this project dir"
                << std::endl;
    } else {
      std::cout << "unknown res" << std::endl;
    }
  } else {
    std::cout << "vfTestPointOnSurfaceByProject falied" << std::endl;
  }
}

void TestFindLoopAndFace(std::string const &arg) {

  std::vector<std::string> edgeIdArr;
  boost::split(edgeIdArr, arg, boost::is_any_of(" "));
  if (edgeIdArr.empty())
    return;

  // last is face id
  const char *faceIdStr = edgeIdArr.back().c_str();
  edgeIdArr.pop_back();
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "lick tgcad failed" << std::endl;
    return;
  };
  const char **edgeIdStrs = new const char *[edgeIdArr.size() + 1] { nullptr };
  const char *loopId = nullptr;
  for (int i = 0; i < edgeIdArr.size(); i++) {
    edgeIdStrs[i] = edgeIdArr[i].c_str();
  }

  const char *findFaceStr = nullptr;
  status = VFAdapter::vfCreateSurfaceByFill(edgeIdStrs, faceIdStr, findFaceStr);
  if (status == VFAdapter::vf_Success) {
    std::cout << "find loop and highlight successfully,loop id is "
              << std::endl;
  } else {
    std::cout << "find loop and highlight failed" << std::endl;
  }

  delete[] edgeIdStrs;
}

void TestDelLoopFace(std::string const &loopId) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "lick tgcad failed" << std::endl;
    return;
  };

  // status = VFAdapter::vfChangeSurfaceColorFromMap(loopId.c_str());
  // if (status == VFAdapter::vf_Success) {
  //   std::cout << "vfChangeSurfaceColorFromMapsuccessfully" << std::endl;
  // } else {
  //   std::cout << "vfChangeSurfaceColorFromMap failed" << std::endl;
  // }
}

void TestSplitCurve(std::string const &arg) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);

  if (status != VFAdapter::vf_Success) {
    std::cout << "lick tgcad failed" << std::endl;
    return;
  };

  std::vector<std::string> argArr;
  boost::split(argArr, arg, boost::is_any_of(" "));
  if (argArr.size() != 5) {
    std::cout << "Please input 5 args ,0 is curveId ,1 is splitPointId ,2 is "
                 "splitType,3 is cvIdOriention, 4 is cvId2oRiention"
              << std::endl;
  }

  std::string curveToTrimId = argArr[0];
  std::string curveTrimingId = argArr[1];
  std::string splitType = argArr[2];
  std::string cvIdOrientation = argArr[3];
  std::string cvId2Orientation = argArr[4];
  status = VFAdapter::vfCreateSplitOrTrim(
      curveToTrimId.c_str(), curveTrimingId.c_str(), splitType.c_str(),
      std::stoi(cvIdOrientation), std::stoi(cvId2Orientation));
  if (status == VFAdapter::vf_Success) {
    std::cout << "split curve success" << std::endl;
  } else {
    std::cout << "split curve failed" << std::endl;
  }
}

void TestSectionIdToMore(std::string const &arg) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  std::wstring filterTypeStr = Utf8ToUnicode(arg.c_str());

  const char **res = nullptr;
  status = VFAdapter::vfSelectionToIDMore(filterTypeStr.c_str(), res);
  if (status == VFAdapter::vf_Success) {
    std::string strRes = "Has select ";
    int cnt = 0;
    const char **resOld = res;
    while (*res) {
      strRes += *res;
      strRes += ",";
      free((void *)(*res));
      res++;
      cnt++;
    }
    delete[] resOld;
    std::cout << strRes << "total:" << cnt << std::endl;
  } else {
    std::cout << "cancel select or select error" << std::endl;
  }
}

void TestCreatePointNormal(std::vector<std::string> const &parmArr) {
  std::cout << "Test Create Normal From Point of Surface " << std::endl;
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);

  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  std::string surfaceid = parmArr[0];
  std::string ptid = parmArr[1];
  VFAdapter::vfCreateNormalLineAndArrowhead(surfaceid.c_str(), ptid.c_str());
}

void TestDeletePointNormal(std::vector<std::string> const &parmArr) {
  std::cout << "Test Create Normal From Point of Surface " << std::endl;
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);

  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  std::string ptid = parmArr[0];
  VFAdapter::vfDeleteNormalLineAndArrowhead(ptid.c_str());
}

void TestClearPersistData() {

  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  VFAdapter::ClearPersistData();
}

void TestActiveDocName() {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  BSTR actDocName;
  status = VFAdapter::vfGetActiveDocumentName(actDocName);
  if (status == VFAdapter::vf_Success) {
    _bstr_t docName = actDocName;
    std::cout << "active doc name is " << docName.operator const char *()
              << std::endl;
  } else {
    std::cout << "get active doc name failed" << std::endl;
  }
}
void TestDismantleCurve(std::string cvId) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  const char **lineOrCvs;
  int length;
  const char **SubCvIds;
  status =
      VFAdapter::vfDismantleCurve(cvId.c_str(), SubCvIds, lineOrCvs, length);
  if (status == VFAdapter::vf_Success) {
    std::cout << "dismantle curve success" << std::endl;
  } else {
    std::cout << "dismantle curve failed" << std::endl;
  }
}

void TestCvStEn(std::string cvId) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  double stX, stY, stZ, enX, enY, enZ;
  status = VFAdapter::vfGetCurveStartAndEndPointCoordinates(
      cvId.c_str(), stX, stY, stZ, enX, enY, enZ);
  if (status == VFAdapter::vf_Success) {
    std::cout << "get curve start and end point success" << std::endl;
    std::cout << "start point is (" << stX << "," << stY << "," << stZ << ")"
              << std::endl;
    std::cout << "end point is (" << enX << "," << enY << "," << enZ << ")"
              << std::endl;
  } else {
    std::cout << "get curve start and end point failed" << std::endl;
  }
}

void TestEqDisPtsOnCv(std::vector<std::string> cvId) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  if (cvId.size() != 2) {
    std::cout << "please input 2 args ,0 is curveId ,1 is pointNum"
              << std::endl;
    return;
  }

  double *X = nullptr, *Y = nullptr, *Z = nullptr;
  int ptCnt = std::stoull(cvId[1]);
  status =
      VFAdapter::vfGetEquidistantPointsOnCurve(cvId[0].c_str(), ptCnt, X, Y, Z);
  if (status == VFAdapter::vf_Success) {
    for (int i = 0; i < ptCnt; i++) {
      std::cout << "point " << i << " is (" << X[i] << "," << Y[i] << ","
                << Z[i] << ")" << std::endl;
      const char *ptId = nullptr;
      VFAdapter::vfCreatePoint(X[i], Y[i], Z[i], ptId);
      if (ptId) {
        free((void *)ptId);
      }
    }
  } else {
    std::cout << "get equidistant points on curve failed" << std::endl;
  }
}

void TestMinDisPtToSurface(std::vector<std::string> args) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  if (args.size() != 4) {
    std::cout
        << "please input 4 args ,0 is surfaceid ,[1-3] is point coordinates"
        << std::endl;
    return;
  }
  double x = std::stod(args[1]);
  double y = std::stod(args[2]);
  double z = std::stod(args[3]);
  double minDis;
  double minX, minY, minZ;
  status = VFAdapter::vfGetMinimumDistancePointCoordinates(
      args[0].c_str(), x, y, z, minX, minY, minZ);
  if (status == VFAdapter::vf_Success) {
    int64_t lineId;
    VFAdapter::TGCreateLineStartEnd(x, y, z, minX, minY, minZ, lineId);
    std::cout << "min distance point is (" << minX << "," << minY << "," << minZ
              << ")" << std::endl;
  } else {
    std::cout << "get minimum distance point failed" << std::endl;
  }
}

void TestCreateSpl2d() {
  // 创建二维样条曲线
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  _bstr_t spl2dName = "哈哈123";
  int plane = 0;
  // int Plane：基准面0为XY平面，1为YZ平面，2为XZ平面；
  constexpr int ptLen = 160;
  double xCoords[ptLen] = {
      369.503,  340.294,  311.234,  282.031,  252.967,  223.767,  194.701,
      165.502,  136.437,  107.236,  41.8547,  49.0148,  19.8844,  -9.24609,
      -38.3765, -52.4926, -96.6158, -125.854, -154.878, -184.152, -213.141,
      -242.5,   -271.403, -301.145, -301.145, -301.116, -301.116, -300.628,
      -300.554, -300.55,  -300.55,  -300.55,  -300.55,  -300.55,  -300.55,
      -300.55,  -300.55,  -300.55,  -300.55,  -300.55,  -300.55,  -300.55,
      -300.55,  -300.55,  -300.55,  -300.55,  -300.55,  -300.55,  -300.55,
      -300.57,  -300.551, -300.752, -301.276, -300.691, -300.551, -300.55,
      -300.55,  -300.55,  -300.55,  -300.55,  -300.55,  -300.55,  -300.55,
      -300.55,  -300.55,  -300.55,  -300.55,  -300.55,  -300.55,  -300.55,
      -300.55,  -300.55,  -300.55,  -300.55,  -300.55,  -300.55,  -300.551,
      -300.671, -300.671, -300.685, -300.685, -271.417, -242.326, -213.156,
      -184.049, -154.895, -125.782, -96.6338, -52.4926, -38.3765, -9.24609,
      19.8844,  49.0148,  41.8547,  107.269,  136.412,  165.531,  194.672,
      223.792,  252.934,  282.054,  311.196,  340.315,  369.458,  369.458,
      369.457,  369.457,  369.45,   369.45,   369.45,   369.45,   369.45,
      369.45,   369.45,   369.45,   369.45,   369.45,   369.45,   369.45,
      369.45,   369.45,   369.45,   369.45,   369.45,   369.45,   369.45,
      369.45,   369.45,   369.45,   369.45,   369.459,  369.519,  369.463,
      369.45,   369.451,  369.45,   369.45,   369.45,   369.45,   369.45,
      369.45,   369.45,   369.45,   369.45,   369.45,   369.45,   369.45,
      369.45,   369.45,   369.45,   369.45,   369.45,   369.45,   369.45,
      369.45,   369.45,   369.454,  369.499,  369.499,  369.503,
  };
  double yCoords[ptLen] = {
      -772.573, -772.573, -772.573, -772.573, -772.573, -772.573, -772.573,
      -772.573, -772.573, -772.573, -772.583, -772.583, -772.583, -772.583,
      -772.583, -772.583, -772.573, -772.573, -772.573, -772.573, -772.573,
      -772.573, -772.573, -772.573, -772.573, -771.617, -771.617, -741.858,
      -727.906, -682.326, -652.559, -622.794, -593.026, -563.259, -533.494,
      -503.727, -473.959, -444.192, -414.426, -384.66,  -354.892, -325.126,
      -295.358, -265.592, -235.826, -206.059, -176.292, -146.525, -116.758,
      -33.0089, -57.225,  -27.4622, 2.32121,  32.0789,  58.1576,  91.6093,
      121.376,  151.143,  180.91,   210.677,  240.443,  270.209,  299.976,
      329.743,  359.511,  389.277,  419.043,  448.81,   478.578,  508.345,
      538.11,   567.876,  597.645,  627.41,   657.177,  686.945,  723.289,
      746.474,  746.474,  747.431,  747.431,  747.431,  747.431,  747.431,
      747.431,  747.431,  747.431,  747.431,  747.434,  747.434,  747.434,
      747.434,  747.434,  747.434,  747.431,  747.431,  747.431,  747.431,
      747.431,  747.431,  747.431,  747.431,  747.431,  747.431,  747.431,
      746.474,  746.474,  723.289,  686.945,  657.177,  627.41,   597.645,
      567.876,  538.11,   508.345,  478.578,  448.81,   419.043,  389.277,
      359.511,  329.743,  299.976,  270.209,  240.443,  210.677,  180.91,
      151.143,  121.376,  91.6093,  58.1576,  32.0789,  2.32121,  -27.4622,
      -57.225,  -33.0089, -116.758, -146.525, -176.292, -206.059, -235.826,
      -265.592, -295.358, -325.126, -354.892, -384.66,  -414.426, -444.192,
      -473.959, -503.727, -533.494, -563.259, -593.026, -622.794, -652.559,
      -682.326, -727.906, -741.858, -771.617, -771.617, -772.573,
  };
  status =
      VFAdapter::vfCreateSpline2D(spl2dName, plane, ptLen, xCoords, yCoords);
  if (status == VFAdapter::vf_Success) {
    std::cout << "create spl2d success" << std::endl;
  } else {
    std::cout << "create spl2d failed" << std::endl;
  }
}

void TestGetPointCoord(std::string const &ptId) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  int prec = std::numeric_limits<double>::digits10;
  std::cout.precision(prec);

  double x, y, z;
  status = VFAdapter::vfGetCoordOfPoint(ptId.c_str(), x, y, z);
  if (status == VFAdapter::vf_Success) {
    std::cout << "point coord is (" << x << "," << y << "," << z << ")"
              << std::endl;
  } else {
    std::cout << "get point coord failed" << std::endl;
  }
}

void TestCreateLineByPtDir(std::vector<std::string> const &args) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  if (args.size() != 6) {
    return;
  }

  // 前三个为起点数据
  // 后三个为 方向
  double ptX = std::stod(args[0]);
  double ptY = std::stod(args[1]);
  double ptZ = std::stod(args[2]);

  double dirX = std::stod(args[3]);
  double dirY = std::stod(args[4]);
  double dirZ = std::stod(args[5]);

  int64_t lineId;
  status = VFAdapter::TGCreateLineStartDirection(ptX, ptY, ptZ, dirX * 10,
                                                 dirY * 10, dirZ * 10, lineId);
  if (status == VFAdapter::vf_Success) {
    std::cout << "create line success,line id:" << lineId << std::endl;
  } else {
    std::cout << "create line failed" << std::endl;
  }
}

void TestCreateLineByPtStEn(std::vector<std::string> const &args) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  if (args.size() != 6) {
    return;
  }

  // 前三个为起点数据
  // 后三个为 方向
  double stX = std::stod(args[0]);
  double stY = std::stod(args[1]);
  double stZ = std::stod(args[2]);

  double enX = std::stod(args[3]);
  double enY = std::stod(args[4]);
  double enZ = std::stod(args[5]);

  int64_t lineId;
  status =
      VFAdapter::TGCreateLineStartEnd(stX, stY, stZ, enX, enY, enZ, lineId);
  if (status == VFAdapter::vf_Success) {
    std::cout << "create line success,line id:" << lineId << std::endl;
  } else {
    std::cout << "create line failed" << std::endl;
  }
}

void TestBatchDelEntites(std::vector<std::string> const &entIds) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  std::vector<int64_t> vecIds;
  for (auto entId : entIds) {
    vecIds.push_back(std::stoull(entId));
  }

  status = VFAdapter::TGBatchDeleteEntities(vecIds);
  if (status == VFAdapter::vf_Success) {
    std::cout << "批量删除成功" << std::endl;
  } else {
    std::cout << "批量删除失败" << std::endl;
  }
}

void TestHilitSurfSet(std::vector<std::string> const &faceIds) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  int clrRed = RGB(255, 0, 0);
  int clrGreen = RGB(0, 255, 0);
  int clrBlue = RGB(0, 0, 255);
  const char **faceIdsStr = new const char *[faceIds.size() + 1];
  memset(faceIdsStr, 0, sizeof(const char *) * (faceIds.size() + 1));
  int *clrRs = new int[faceIds.size()];
  int *clrGs = new int[faceIds.size()];
  int *clrBs = new int[faceIds.size()];

  for (size_t i = 0; i < faceIds.size(); ++i) {
    auto faceIdStr = faceIds[i];
    faceIdsStr[i] = _strdup(faceIdStr.c_str());
    clrRs[i] = i % 3 == 0 ? 255 : 0;
    clrGs[i] = i % 3 == 1 ? 255 : 0;
    clrBs[i] = i % 3 == 2 ? 255 : 0;
  }

  status =
      VFAdapter::vfChangeSurfaceColorInsertMap(faceIdsStr, clrRs, clrGs, clrBs);

  if (status == VFAdapter::vf_Success) {
    std::cout << "设置颜色成功" << std::endl;
  } else {
    std::cout << "设置颜色失败" << std::endl;
  }

  delete[] clrGs;
  delete[] clrRs;
  delete[] clrBs;
  for (size_t i = 0; i < faceIds.size(); ++i) {
    if (faceIdsStr[i]) {
      free((void *)faceIdsStr[i]);
    }
  }
}

void TestClrHilitSurfSet(std::vector<std::string> const &faceIds) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  const char **faceIdsStr = new const char *[faceIds.size() + 1];
  memset(faceIdsStr, 0, sizeof(const char *) * (faceIds.size() + 1));

  for (size_t i = 0; i < faceIds.size(); ++i) {
    auto faceIdStr = faceIds[i];
    faceIdsStr[i] = _strdup(faceIdStr.c_str());
  }

  status = VFAdapter::vfChangeSurfaceColorFromMap(faceIdsStr);
  if (status == VFAdapter::vf_Success) {
    std::cout << "设置颜色成功" << std::endl;
  } else {
    std::cout << "设置颜色失败" << std::endl;
  }
}

void TestTriOfExEndPt(std::vector<std::string> const &args) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  if (4 != args.size()) {
    std::cout << "请输入三个参数，分别为线id集，点id集，延伸数值集,所在面"
                 "每个集合之间以逗号结尾"
              << std::endl;
    return;
  }

  std::vector<std::string> strCurveIdStrArr, ptIdStrArr, extendValStrArr;
  strCurveIdStrArr =
      boost::split(strCurveIdStrArr, args[0], boost::is_any_of(","));
  ptIdStrArr = boost::split(ptIdStrArr, args[1], boost::is_any_of(","));
  extendValStrArr =
      boost::split(extendValStrArr, args[2], boost::is_any_of(","));
  std::string faceId = args[3];
  if (strCurveIdStrArr.empty() ||
      strCurveIdStrArr.size() != ptIdStrArr.size() ||
      strCurveIdStrArr.size() != extendValStrArr.size()) {
    std::cout << "三个集合之间数目应一致" << std::endl;
    return;
  }

  std::vector<const char *> curveIdsVec(strCurveIdStrArr.size() + 1);
  curveIdsVec.back() = nullptr;

  for (int i = 0; i < strCurveIdStrArr.size(); i++) {
    curveIdsVec[i] = strCurveIdStrArr[i].c_str();
  }

  std::vector<double> x(strCurveIdStrArr.size() + 1);
  x.back() = NAN;
  std::vector<double> y(x), z(x), extendVals(x);

  for (int i = 0; i < ptIdStrArr.size(); i++) {
    VFAdapter::vfGetCoordOfPoint(ptIdStrArr[i].c_str(), x[i], y[i], z[i]);
    extendVals[i] = stod(extendValStrArr[i]);
  }

  status = VFAdapter::vfTrimOrExtendCurvesFromEndPoint(
      curveIdsVec.data(), faceId.c_str(), x.data(), y.data(), z.data(),
      extendVals.data());
  if (status != VFAdapter::vfHRESULT::vf_Success) {
    std::cout << "调用函数失败" << std::endl;
    return;
  } else {
    std::cout << "调用函数成功" << std::endl;
    return;
  }
  return;
}

void TestCtGeodCvByTwoPt(std::vector<std::string> const &ptIds) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  if (3 != ptIds.size()) {
    std::cout << "参数个数错误, 请输入两个点id，最后为面id" << std::endl;
    return;
  }

  std::vector<double> x1(2, NAN), y1, z1, x2, y2, z2;
  y1 = z1 = x2 = y2 = z2 = x1;
  std::string ptIdFstStr = ptIds[0];
  std::string ptIdSecStr = ptIds[1];
  std::string surfaceID = ptIds[2];
  VFAdapter::vfGetCoordOfPoint(ptIdFstStr.c_str(), x1[0], y1[0], z1[0]);
  VFAdapter::vfGetCoordOfPoint(ptIdSecStr.c_str(), x2[0], y2[0], z2[0]);

  status = VFAdapter::vfCreateCurveOnSurfaceByTwoPoints(
      x1.data(), y1.data(), z1.data(), x2.data(), y2.data(), z2.data(),
      surfaceID.c_str());
  if (status == VFAdapter::vf_Success) {
    std::cout << "在曲面上根据点创建曲线成功" << std::endl;
  } else {
    std::cout << "在曲面上根据点创建曲线失败" << std::endl;
  }
}

void TestBatchOfCvOnSurf(std::vector<std::string> const &args) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  if (args.size() != 4) {
    std::cout << "参数个数错误, "
                 "请输入4个参数,分别为线id,面id,头偏移数组(MM)，尾偏移数组(MM)"
              << std::endl;
    return;
  }

  std::string lineID = args[0];
  std::string surfaceID = args[1];
  std::vector<std::string> headOffsetStr, tailOffsetStr;
  headOffsetStr = boost::split(headOffsetStr, args[2], boost::is_any_of(","));
  tailOffsetStr = boost::split(tailOffsetStr, args[3], boost::is_any_of(","));
  if (headOffsetStr.size() != tailOffsetStr.size()) {
    std::cout << "头尾偏移数组个数不一致" << std::endl;
    return;
  }

  std::vector<double> headOffset(headOffsetStr.size() + 1),
      tailOffset(headOffsetStr.size() + 1);
  headOffset.back() = tailOffset.back() = NAN;

  for (size_t i = 0; i < headOffsetStr.size(); ++i) {
    headOffset[i] = std::stod(headOffsetStr[i]);
    tailOffset[i] = std::stod(tailOffsetStr[i]);
  }

  const char **offsetdCvIds = nullptr;
  status = VFAdapter::vfOffsetCurveByStartPointAndEndPoint(
      surfaceID.c_str(), lineID.c_str(), "true", headOffset.data(),
      tailOffset.data(), offsetdCvIds);
  if (status == VFAdapter::vf_Success) {
    std::cout << "批量创建曲线成功" << std::endl;
    delete[] offsetdCvIds;
  } else {
    std::cout << "批量创建曲线失败" << std::endl;
  }
}

void TestSaveDataToDoc(std::string path) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  std::wstring wstr =
      L"E:\\COMAC\\商飞6月适配\\CCDS_AlfaV0.1-2\\CompositeDB.db3";
  status = VFAdapter::vfDataTableSave(const_cast<BSTR>(wstr.c_str()));
  return;
}

void TestRetriveDataToDB(std::string path) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }
  std::wstring wstr = L"E:\\COMAC\\商飞6月适配\\CCDS_AlfaV0.1-2\\testDB111.db3";
  status = VFAdapter::vfDataTableRetrive(const_cast<BSTR>(wstr.c_str()));
  return;
}

void TestCreatGeodesicCurvebyPoint(std::vector<std::string> const &args) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  if (args.size() != 6) {
    std::cout << "参数个数错误, "
                 "请输入6个参数,分别为点id,边界id,曲面id,矢量方向坐标(XYZ)"
              << std::endl;
    return;
  }

  std::string idPoint = args[0];
  std::string idBoundary = args[1];
  std::string idSurface = args[2];
  std::string xStr = args[3];
  std::string yStr = args[4];
  std::string zStr = args[5];

  double dirX = std::stod(xStr);
  double dirY = std::stod(yStr);
  double dirZ = std::stod(zStr);

  double ptX, ptY, ptZ;
  status = VFAdapter::vfGetCoordOfPoint(idPoint.c_str(), ptX, ptY, ptZ);
  if (status != VFAdapter::vf_Success) {
    std::cout << "获取点坐标失败" << std::endl;
    return;
  }

  _bstr_t geodCvName = L"cv0";
  _bstr_t geomSetName = L"geomSet0";

  const char *newCurveID = nullptr;

  status = VFAdapter::vfCreatGeodesicCurvebyPoint(
      idBoundary.c_str(), idSurface.c_str(), ptX, ptY, ptZ, dirX, dirY, dirZ,
      geodCvName, geomSetName, newCurveID);
  if (status == VFAdapter::vf_Success) {
    std::cout << "在环内一点沿着某方向做线成功" << std::endl;
    std::cout << "新创建的曲线id为: " << newCurveID << std::endl;
    free((void *)newCurveID);
  } else {
    std::cout << "创建 geodesic curve 失败" << std::endl;
  }
}

void TestGetBoundaryIDbyDivide(std::vector<std::string> const &args) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  if (args.size() != 5) {
    std::cout
        << "参数个数错误, "
           "请输入5个参数,分别为空间点id,边界id,曲面id,分割曲线1id,分割曲线2id"
        << std::endl;
    return;
  }

  std::string idPoint = args[0];
  std::string idBoundary = args[1];
  std::string idSurface = args[2];
  std::string idSplitCv1 = args[3];
  std::string idSplitCv2 = args[4];

  double ptX, ptY, ptZ;
  status = VFAdapter::vfGetCoordOfPoint(idPoint.c_str(), ptX, ptY, ptZ);
  if (status != VFAdapter::vf_Success) {
    std::cout << "获取点坐标失败" << std::endl;
    return;
  }

  const char *newBoundaryId = nullptr;
  status = VFAdapter::vfGetBoundaryIDbyDivide(
      idBoundary.c_str(), idSurface.c_str(), ptX, ptY, ptZ, idSplitCv1.c_str(),
      idSplitCv2.c_str(), newBoundaryId);
  if (status == VFAdapter::vf_Success) {
    std::cout << "提取点所在环ID成功" << std::endl;
    std::cout << "新创建的边界id为: " << newBoundaryId << std::endl;
    free((void *)newBoundaryId);
  } else {
    std::cout << "获取边界id失败" << std::endl;
  }
}

void TestSaveasStp() {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  _bstr_t filePath = L"D:\\";
  _bstr_t fileName = L"test";
  status = VFAdapter::vfSaveasStp(fileName, filePath);
  if (status == VFAdapter::vf_Success) {
    std::cout << "保存成功" << std::endl;
  } else {
    std::cout << "保存失败" << std::endl;
  }
}

void TestGetBoundaryIDbyPoint(std::vector<std::string> const &args) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "连接天工CAD失败" << std::endl;
    return;
  }

  if (args.size() < 4) {
    std::cout << "参数个数错误, "
                 "请输入至少4个参数,分别为空间点id,边界id,曲面id,分割曲线集ids"
              << std::endl;
    return;
  }
  std::string idPoint = args[0];
  std::string idBoundary = args[1];
  std::string idSurface = args[2];
  std::vector<const char *> divideIds(args.size() - 3 + 1, nullptr);
  for (int i = 3; i < args.size(); i++) {
    divideIds[i - 3] = args[i].c_str();
  }

  double ptX, ptY, ptZ;
  status = VFAdapter::vfGetCoordOfPoint(idPoint.c_str(), ptX, ptY, ptZ);
  if (status != VFAdapter::vf_Success) {
    std::cout << "获取空间点坐标失败" << std::endl;
    return;
  }

  const char **pDivideIds = divideIds.data();
  const char *newBoundaryId = nullptr;
  const char *newSurfaceId = nullptr;
  status = VFAdapter::vfGetBoundaryIDbyPoint(
      idBoundary.c_str(), idSurface.c_str(), ptX, ptY, ptZ, pDivideIds,
      newBoundaryId, newSurfaceId);
  if (status != VFAdapter::vf_Success) {
    std::cout << "获取边界ID失败" << std::endl;
    return;
  } else {
    std::cout << "提取点所在环ID（数组形式输入切割线）成功" << std::endl;
    std::cout << "剪口ID为：" << newBoundaryId << std::endl;
    free((void *)newBoundaryId);
    free((void *)newSurfaceId);
  }
}

void TestCreateSlitDart(std::vector<std::string> const &args) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "启动CAD失败" << std::endl;
    return;
  }

  if (args.size() != 5) {
    std::cout << "参数个数错误" << std::endl;
    std::cout << "<PointID1> <PointID2> "
                 "<boundaryId> <surfaceId> <dartLength>"
              << std::endl;
    return;
  }

  std::string idPoint1 = args[0];
  std::string idPoint2 = args[1];

  std::string idBoundary = args[2];
  std::string idSurface = args[3];
  double dartLength = std::stod(args[4]);
  double ptX1, ptY1, ptZ1, ptX2, ptY2, ptZ2;

  status = VFAdapter::vfGetCoordOfPoint(idPoint1.c_str(), ptX1, ptY1, ptZ1);
  status = VFAdapter::vfGetCoordOfPoint(idPoint2.c_str(), ptX2, ptY2, ptZ2);

  const char *newBoundaryID = nullptr;
  status = VFAdapter::vfCreateSlitDart(idSurface.c_str(), idBoundary.c_str(),
                                       dartLength, ptX1, ptY1, ptZ1, ptX2, ptY2,
                                       ptZ2, newBoundaryID);

  if (status != VFAdapter::vf_Success) {
    std::cout << "vfCreateSlitDart失败" << std::endl;
    return;
  } else {
    std::cout << "vfCreateSlitDart成功" << std::endl;
    std::cout << "新边界ID为:" << newBoundaryID << std::endl;
    free((void *)newBoundaryID);
  }
}
void TestCreateVShapeDart(std::vector<std::string> const &args) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "启动CAD失败" << std::endl;
    return;
  }

  if (args.size() != 5) {
    std::cout << "参数个数错误" << std::endl;
    std::cout << "<PointID1> <PointID2> "
                 "<boundaryId> <surfaceId> <dartLength>"
              << std::endl;
    return;
  }

  std::string idPoint1 = args[0];
  std::string idPoint2 = args[1];
  std::string idPoint3 = args[2];

  std::string idBoundary = args[3];
  std::string idSurface = args[4];

  double ptX1, ptY1, ptZ1, ptX2, ptY2, ptZ2, ptX3, ptY3, ptZ3;
  status = VFAdapter::vfGetCoordOfPoint(idPoint1.c_str(), ptX1, ptY1, ptZ1);
  status = VFAdapter::vfGetCoordOfPoint(idPoint2.c_str(), ptX2, ptY2, ptZ2);
  status = VFAdapter::vfGetCoordOfPoint(idPoint3.c_str(), ptX3, ptY3, ptZ3);

  const char *newBoundaryID = nullptr;
  status = VFAdapter::vfCreateVShapeDart(idSurface.c_str(), idBoundary.c_str(),
                                         ptX1, ptY1, ptZ1, ptX2, ptY2, ptZ2,
                                         ptX3, ptY3, ptZ3, newBoundaryID);

  if (status != VFAdapter::vf_Success) {
    std::cout << "创建V形剪口失败" << std::endl;
    return;
  } else {
    std::cout << "创建V形剪口成功" << std::endl;
    std::cout << "剪口ID为:" << newBoundaryID << std::endl;
    free((void *)newBoundaryID);
  }
}

void Test3dSection() {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "启动CAD失败" << std::endl;
    return;
  }

  std::string laminateName = "laminate001";
  int64_t sectionCvId = 0;
  std::string sectionCvIdStr = std::to_string(sectionCvId);
  status = VFAdapter::VF2Create3Dsection(
      "laminate001", sectionCvIdStr.c_str(), nullptr, nullptr, nullptr, 0.8,
      0.8, nullptr, nullptr, 1e-6, 1e-7, true, nullptr, true, nullptr);
}

void TestChangeLinesColorAndWidth(std::vector<std::string> const &ids) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "启动CAD失败" << std::endl;
    return;
  }

  const char **pStrArr = new const char *[ids.size() + 1];
  std::vector<int> R(ids.size()), G(ids.size()), B(ids.size());
  std::vector<double> lineWidth(ids.size());

  memset(pStrArr, 0, sizeof(const char *) * (ids.size() + 1));
  for (int i = 0; i < ids.size(); i++) {
    pStrArr[i] = ids[i].c_str();
    R[i] = 0;
    G[i] = B[i] = 255;
    lineWidth[i] = 3.0;
  }

  status = VFAdapter::vfChangeLinesColorAndWidth(pStrArr, R.data(), G.data(),
                                                 B.data(), lineWidth.data());
  delete[] pStrArr;
}
void TestGetLinesColorAndWidth(std::vector<std::string> const &ids) {

  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "启动CAD失败" << std::endl;
    return;
  }
  const char **pStrArr = new const char *[ids.size() + 1];
  memset(pStrArr, 0, sizeof(const char *) * (ids.size() + 1));
  for (int i = 0; i < ids.size(); i++) {
    pStrArr[i] = ids[i].c_str();
  }

  int *R = nullptr, *G = nullptr, *B = nullptr;
  double *lineWidth = nullptr;
  status = VFAdapter::vfGetLinesColorAndWidth(pStrArr, R, G, B, lineWidth);

  if (R) {
    delete[] R;
  }
  if (G) {
    delete[] G;
  }
  if (B) {
    delete[] B;
  }
  if (lineWidth) {
    delete[] lineWidth;
  }
}

void TestJoin(std::vector<std::string> const &ids) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "启动CAD失败" << std::endl;
    return;
  }

  const char **pStrArr = new const char *[ids.size() + 1];
  memset(pStrArr, 0, sizeof(const char *) * (ids.size() + 1));
  for (int i = 0; i < ids.size(); i++) {
    pStrArr[i] = ids[i].c_str();
  }

  const char *joinCurveId = nullptr;
  status = VFAdapter::vfCreateJoin(pStrArr, joinCurveId);
  if (status == VFAdapter::vf_Success) {
    std::cout << "Join成功,curveId:" << joinCurveId << std::endl;
  } else {
    std::cout << "Join失败" << std::endl;
  }
  if (joinCurveId) {
    free((void *)joinCurveId);
  }
}

void TestPickPointCoord(std::vector<std::string> const &args) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "启动CAD失败" << std::endl;
    return;
  }

  if (args.size() != 2) {
    std::cout << "参数个数错误" << std::endl;
    std::cout << "<SurfaceID> <PointNum>" << std::endl;
    return;
  }

  int pointNum = std::stoull(args[1]);
  double *X = nullptr, *Y = nullptr, *Z = nullptr;
  status = VFAdapter::vfPickPointCoord(args[0].c_str(), pointNum, X, Y, Z);
  if (status == VFAdapter::vf_Success) {
    std::cout << "获取点坐标成功" << std::endl;
    for (int i = 0; i < pointNum; i++) {
      std::cout << "pt" << i << ":(" << X[i] << "," << Y[i] << "," << Z[i]
                << ")" << std::endl;
    }
    delete[] X;
    delete[] Y;
    delete[] Z;
  } else {
    std::cout << "获取点坐标失败" << std::endl;
  }
}

void CreateNewDartBoundary(std::vector<std::string> const &args) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "启动CAD失败" << std::endl;
    return;
  }

  if (args.size() != 6) {
    std::cout << "参数个数错误" << std::endl;
    std::cout << "面 边界 剪口 x y z" << std::endl;
    return;
  }
  const char *newBoundaryId = nullptr;
  double x = std::stod(args[3]), y = std::stod(args[4]), z = std::stod(args[5]);
  status = VFAdapter::vfCreateNewDartBoundary(args[0].c_str(), args[1].c_str(),
                                              args[2].c_str(), x, y, z,
                                              newBoundaryId);

  if (newBoundaryId) {
    std::cout << "创建V形剪口成功:" << newBoundaryId << std::endl;
    free((void *)newBoundaryId);
  }
}
void TestCurveOnSurface(std::vector<std::string> const &args) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "启动CAD失败" << std::endl;
    return;
  }

  if (args.size() != 3) {
    std::cout << "参数个数错误" << std::endl;
    std::cout << "依次输入面 曲线 环" << std::endl;
    return;
  }
  int res;
  status = VFAdapter::vfTestCurveOnSurface(args[0].c_str(), args[2].c_str(),
                                           args[1].c_str(), res);
  std::cout << "结果:" << res << std::endl;
}
void CreateSpliteCurve(std::vector<std::string> const &args) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "启动CAD失败" << std::endl;
    return;
  }

  if (args.size() != 3) {
    std::cout << "参数个数错误" << std::endl;
    std::cout << "依次输入面  曲线 边界" << std::endl;
    return;
  }
  const char *newCurveId = nullptr;
  status = VFAdapter::vfCreateSpliteCurve(args[0].c_str(), args[1].c_str(),
                                          args[2].c_str(), newCurveId);

  if (newCurveId) {
    std::cout << "生成截线成功:" << newCurveId << std::endl;
    free((void *)newCurveId);
  }
}
void TestTypeOfSurfaceAndGetGeneratrixVector(
    std::vector<std::string> const &args) {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "启动CAD失败" << std::endl;
    return;
  }

  if (args.size() != 3) {
    std::cout << "参数个数错误" << std::endl;
    std::cout << "依次输入面 目标点 方向点" << std::endl;
    return;
  }

  double x1, y1, z1;
  double x2, y2, z2;
  status = VFAdapter::vfGetCoordOfPoint(args[1].c_str(), x1, y1, z1);
  if (status != VFAdapter::vf_Success) {
    std::cout << "获取点坐标失败" << std::endl;
    return;
  }

  status = VFAdapter::vfGetCoordOfPoint(args[2].c_str(), x2, y2, z2);
  if (status != VFAdapter::vf_Success) {
    std::cout << "获取点坐标失败" << std::endl;
    return;
  }

  int type;
  double x, y, z;
  status = VFAdapter::vfTestTypeOfSurfaceAndGetGeneratrixVector(
      args[0].c_str(), x1, y1, z1, x2, y2, z2, x, y, z, type);
  if (status == VFAdapter::vf_Success) {
    std::cout << "结果:" << type << "(" << x << "," << y << "," << z << ")";
  }
}

void TestMBD() {
  VFAdapter::vfHRESULT status =
      VFAdapter::vfStartLinkWithCAD(VFAdapter::TGC_CODE);
  if (status != VFAdapter::vf_Success) {
    std::cout << "启动CAD失败" << std::endl;
    return;
  }

  auto curPath = std::filesystem::current_path();
  bool existMDBTree = std::filesystem::exists("testmbdNode.json");
  bool existGeoTree = std::filesystem::exists("testmGeoNode.json");
  if (!existMDBTree || !existGeoTree) {
    std::cout << "缺少文件: testmbdNode.json testgeoNode.json" << std::endl;
    return;
  }

  std::string geoTree, mbdTree;
  std::ifstream file("testmbdNode.json", std::ios::binary);
  std::stringstream ss;
  ss << file.rdbuf();
  mbdTree = ss.str();
  file.close();

  file.open("testmGeoNode.json", std::ios::binary);
  ss.str("");
  ss << file.rdbuf();
  geoTree = ss.str();
  file.close();

  // std::filesystem file("testmbdNode.json", std::ios::binary);

  auto treeNode1 = jsonToTreeNode(mbdTree);
  auto treeNode2 = jsonToTreeNode(geoTree);
  status = VFAdapter::vfCreateMBD(treeNode1.get(), treeNode2.get());
}
} // namespace tt
